//
//  DQMeViewController.m
//  DQBaisibudejie
//
//  Created by 杜倩 on 16/8/29.
//  Copyright © 2016年 杜倩. All rights reserved.
//

#import "DQMeViewController.h"
#import "UIBarButtonItem+buttonItem.h"
#import "DQTableController.h"
#import "DQMeCell.h"
#import <AFNetworking.h>
#import "DQMeModel.h"
#import "DQCollectionCell.h"
#import "DQThreeCell.h"
@interface DQMeViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tabelView;

//@property(nonatomic,strong)DQCollectionCell *collectioncell;

@end

@implementation DQMeViewController


#pragma mark  viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    [self additem];
    
     self.tabelView.contentInset=
    UIEdgeInsetsMake(-25, 0, 0, 0);//内边距--cell距离navgation的距离
    
    
    //设置three中的cell的分割线
    self.tabelView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
    //设计内边距问题--解决横线顶头问题
    self.tabelView.separatorInset=UIEdgeInsetsMake(0, 0, 0, 0);
    self.tabelView.separatorColor=[UIColor blackColor];
    
//    //设置DQCollectionCell的代理
//    _collectioncell=[[DQCollectionCell alloc] init];
//    _collectioncell.delegate=self;
    

}

-(void)additem{
    UIBarButtonItem *item1=[UIBarButtonItem barButtonItemWith:[UIButton buttonWithType:UIButtonTypeCustom] addTarget:self action:@selector(Click1:) andImage:@"mine-moon-icon" andselectImage:@"mine-sun-icon"];
    UIBarButtonItem *item2=[UIBarButtonItem barButtonItemWith:[UIButton buttonWithType:UIButtonTypeCustom] addTarget:self action:@selector(Click2) andImage:@"mine-setting-icon" andhightLighted:@"mine-sun-icon-click"];
    self.navigationItem.title=@"我的";
    self.navigationItem.rightBarButtonItems=@[item2,item1];
}
#pragma mark 月亮的点击事件--变色
-(void)Click1:(UIButton *)sender{
    sender.selected= !sender.selected;
    
    NSLog(@"%s",__func__);
}

#pragma mark 设置单击事件
-(void)Click2{
    NSLog(@"%s",__func__);
    
    //实现界面跳转
    DQTableController *tableVc=[[DQTableController alloc] init];
    //只能在跳转之前隐藏
    tableVc.hidesBottomBarWhenPushed=YES;//设置点击隐藏tabbar
    [self.navigationController pushViewController:tableVc animated:YES];
    
}

//实现代理的一系列方法
#pragma mark 组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
#pragma mark 组头
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    if (section == 2) {
    return @"推荐订阅";
    }
    return nil;
}
#pragma mark 行数--分行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
    self.tabelView.sectionFooterHeight=1;//设置组低高
        self.tabelView.sectionHeaderHeight = 10;//组头高
        return 1;
    }else if (section ==1){
        return 1;
    }else{
        return 3;
    }
}

#pragma mark cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *tempcell=nil;//临时的cell
    
    //加载collection.xib
    if (indexPath.section == 0) {
        //第二部分
        static NSString *ID=@"head";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
        tempcell=cell;
    }else if (indexPath.section == 1){
        DQMeCell *cell=[[[NSBundle mainBundle] loadNibNamed:@"DQMeCell" owner:nil options:nil] lastObject];//封装性差
        tempcell=cell;
    }else{
        //推荐订阅
        static NSString *ID=@"three";//加载最后的推荐订阅-2
        DQThreeCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
        if (cell== nil) {
            cell=[DQThreeCell threeCell];//调用三中的类方法
        }

        tempcell=cell;
    }
    
    return tempcell;
}
#pragma mark 定义第二行的cell，设置行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        return 180;//第二行的cell的高度
    }else if(indexPath.section==2){
        return 60;//设置三块的行高为60
    }
    return 44;//其他不变
}








@end
